package com.example.friendfindertwo;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.example.friendfindertwo.R;
import com.example.friendfindertwo.EventListFragment.Callbacks;
import com.example.friendfindertwo.EventListFragment.IMenuListFragment;
import model.Event;

public class EventListActivity extends FragmentActivity implements Callbacks, IMenuListFragment{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		Log.i("EventListActivity.onCreate", "start function");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.event_view);


//		if(getIntent().getExtras().getString("objectId") != null){
//			DetailEventFragment detailFragment = new DetailEventFragment();
//			Bundle args = new Bundle();
//			args.putString("objectId", getIntent().getExtras().getString("objectId"));
//			detailFragment.setArguments(args);
//			getSupportFragmentManager()
//			.beginTransaction()
//			.add(R.id.fragment_container, detailFragment)
//			.commit();
//
//			
//		}else{

		EventListFragment eventListFr = new EventListFragment();

		getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, eventListFr).commit();
//		}
		// get action bar   
		ActionBar actionBar = getActionBar();
		// Enabling Up / Back navigation
		actionBar.setDisplayHomeAsUpEnabled(true);

	}

	@Override
	public void onMenuItemSelected(int id) {
		Log.i("EventListActivity.onMenuItemSelected", "start function");
		// TODO Auto-generated method stub
		if (findViewById(R.id.fragment_container) != null) {
			Log.i("EventListActivity.onMenuItemSelected", "function if findViewById");

			// If right panel exists then show selected item details on it
			FragmentTransaction ft = getSupportFragmentManager()
					.beginTransaction();
			//ft.setCustomAnimations(
			//			R.anim.slide_in_top, R.anim.slide_out_right);

			DetailEventFragment detailFragment = new DetailEventFragment();
			Bundle args = new Bundle();
			args.putInt("key", id);
			detailFragment.setArguments(args);

			ft.replace(R.id.fragment_container, detailFragment, detailFragment.TAG);
			ft.addToBackStack(null);
			ft.commit();
			Log.i("EventListActivity.onMenuItemSelected", "end function");

		}
		Log.i("EventListActivity.onMenuItemSelected", "end of if findViewById");


	}

	@Override
	public void onItemEditSelected(int id) {
		// TODO Auto-generated method stub
		Log.i("EventListActivity.onItemEditSelected", "");

	}


}
